import request from '@/axios'
import {
  CreateDictData,
  DictItem,
  DictListResponse,
  DictPageParams,
  DictPageResponse,
  DictUpdateData
} from '@/api/dict/types'

export const createDictApi = (data: CreateDictData): Promise<IResponse> => {
  return request.post({ url: '/dicts/create', data })
}

export const deleteDictApi = (code: string | string[]): Promise<IResponse> => {
  return request.delete({ url: `/dicts/delete/${code}` })
}

export const getDetailDictApi = (code: string): Promise<IResponse<DictItem[]>> => {
  return request.get({ url: `/dicts/detail/${code}` })
}

export const getDictDetailApi = (code: string): Promise<IResponse<DictItem[]>> => {
  return request.get({ url: `/dicts/detail/all/${code}` })
}

export const getDictListApi = (): Promise<IResponse<DictListResponse[]>> => {
  return request.get({ url: `/dicts/list` })
}

export const getDictPageApi = (params: DictPageParams): Promise<IResponse<DictPageResponse[]>> => {
  return request.get({ url: `/dicts/page`, params })
}

export const updateDictApi = (data: DictUpdateData): Promise<IResponse> => {
  return request.put({ url: `/dicts/update/${data.code}`, data })
}
